package BankAndTicket;

/**
 * @author wuhan
 * @date 2019/9/18 19:54
 */

class Ticket implements Runnable{
    public synchronized   void sale() throws InterruptedException {
            if (tick>0){
                Thread.sleep(10);
                System.out.println(Thread.currentThread().getName()+"sale:"+tick--);
            }
    }
    private   int  tick=1000;
    public   void   run(){
        try {
            while (true)
            {
                this.sale();
            }
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
public class TicketJuc {
    public static void main(String[] args) {
        Ticket ticket =new Ticket();
        Thread thread0=new Thread(ticket);
        Thread thread1=new Thread(ticket);
        Thread thread2=new Thread(ticket);
        Thread thread3=new Thread(ticket);

        thread0.start();
        thread1.start();
        thread2.start();
        thread3.start();
    }
}
